package cn.pku.ss.sirx.sna.ib.bean;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

import org.hibernate.annotations.GenericGenerator;

/**
 * Abstract of an influence, containing information on
 * influencer, influencee, date and influence value.
 *
 * @author WangXiao
 * @version 1.0
 */
@Entity
public class Influence {
    
    /**
     * Default constructor.
     */
    public Influence() {}
    
    /**
     * Constructor.
     */
    public Influence(String influencerId, String influenceeId, Date date, double value) {
        this.influencerId = influencerId;
        this.influenceeId = influenceeId;
        this.date = date;
        this.value = value;
    }
    
    public String getInfluencerId() {
        return influencerId;
    }
    public void setInfluencerId(String influencerId) {
        this.influencerId = influencerId;
    }
    public String getInfluenceeId() {
        return influenceeId;
    }
    public void setInfluenceeId(String influenceeId) {
        this.influenceeId = influenceeId;
    }
    public Date getDate() {
        return date;
    }
    public void setDate(Date date) {
        this.date = date;
    }
    public double getValue() {
        return value;
    }
    public void setValue(double value) {
        this.value = value;
    }
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }
        if (obj instanceof Influence) {
            Influence influence = (Influence)obj;
            return influence.getInfluencerId().equals(this.influencerId) &&
                   influence.getInfluenceeId().equals(this.influenceeId) &&
                   influence.getDate().equals(this.date);
        }
        return false;
    }

    @Override
    public int hashCode() {
        int result = this.influencerId.hashCode();
        result += result * 13 + this.influenceeId.hashCode();
        result += result * 13 + this.date.hashCode();
        return result;
    }

    @Override
    public String toString() {
        return String.format("%s to %s: %f at %tD %tT", influencerId, influenceeId, value, date, date);
    }
    
    //////////////////////////////////////////////////////////////////////////////

    private String influencerId;
    private String influenceeId;
    private Date date;
    private double value;
    @Id
    @GeneratedValue(generator="increment")
    @GenericGenerator(name="increment", strategy="increment")
    private Integer id; // as a primary key in database

}
